import { jsonp } from '@/common/js/getData';
import { commonParams, options, ERR_OK } from '@/common/js/config';
import api from './apiUrl';

export function getSingerList() {
  const data = Object.assign({}, commonParams, {
    channel: 'singer',
    page: 'list',
    key: 'all_all_all',
    pagesize: 100,
    pagenum: 1,
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq',
  });
  return jsonp(api.singerList, data, options).then((res) => {
    if (res.code === ERR_OK) {
      return Promise.resolve(res.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}

export function getSingerDetail(singerId) {
  // 根据id查询singer相关信息
  const data = Object.assign({}, commonParams, {
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq',
    order: 'listen',
    begin: 0,
    num: 80,
    songstatus: 1,
    singermid: singerId,
  });

  return jsonp(api.singerDetail, data, options).then((res) => {
    if (ERR_OK === res.code) {
      return Promise.resolve(res.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}
